#################################################################
## Replication for:
## How Judges' Professional Experience Impacts Case Outcomes:
## An Examination of Public Defenders and Criminal Sentencing
## The Journal of Politics
## By Allison Harris and Maya Sen
## Date: July 2024
#################################################################

## Note:
## Sentencing data come from TRAC (sent to us via email from Susan Long on 14 Nov 2021)

## Use of these data must approved and provided via TRAC directly, not from Harris or Sen

## FJC Data come from the Federal Judicial Center (downloaded Nov 2021)
## "Judge Experience Project 1723.csv") is data collected by Yale RAs in March-April of 2023 on criminal defense experience of judges
## DIME Data come from Bonica & Sen, Political Analysis (2019)

#################################################################
## Required packages
#################################################################

library(tidyverse)
library(xtable)
library(stargazer)
library(modelsummary)
library(fixest)
library(systemfonts)
library(psych)
library(lubridate)
library(sandwich)
library(lmtest)

#################################################################
## Data
#################################################################

# from TRAC (proprietary - permission must be secured from TRAC)
charge <- read.csv("charge.csv")
extract <- read.csv("extract.csv") # “defendant files” are prosecutor annual workload files
sentence <-  read.csv("sentence.csv")
history <-  read.csv("history.csv")

# from federal judicial center (publicly available)
fjc <- read.csv("fjc.csv")
careers <- read.csv("federal-judicial-service.csv")

# additional work from RAs (uploaded)
RA.work <- read.csv("Judge Experience Project 1723.csv") # data collected by Yale RAs in march-april of 2023 on criminal defense experience of judges
private <- RA.work[,c("nid","Priv.Criminal.Defense","Notes")]
# Note:
# 1- private criminal defense experience
# 2- only pro bono/internship/externship criminal defense experience
# 3- negligible criminal defense experience (indicates just a few cases throughout entire career in questionnaire or hearing transcript)


RA <- read.csv("public-defenders-JP.csv") # uploaded, collected by another Yale RA team of the number of years of PD experience
RA <- cbind(RA$nid, RA$years.pd)
colnames(RA) <- c("nid","years.pd") 

# additional data on ideology, senate control (uploaded)
senate <- read.csv("senate-control.csv")  # information on Congressional sessions (to include an FE on Congress term)
senate$interval <- interval(ymd(senate$start.session), ymd(senate$end.session))
DIME <- read.csv("bonica_sen_fed_judges.csv") # Bonica & Sen Political Analysis data

# merging DIME data:
fjc <- merge(fjc, DIME, by.x = "jid", by.y = "fjc.judge.idno", all.x = TRUE, all.y = FALSE)
fjc <- merge(fjc, private, by = "nid", all.x = TRUE, all.y = FALSE, suffixes = c("", ".private"))

#################################################################
## Cleaning up sentencing
#################################################################

## Note: sentence$Incarceration.XYZ can be 99999 for life sentences

## for incarceration:

sentence$Incarceration.Tot <- NA
sentence$Incarceration.Days[is.na(sentence$Incarceration.Days)] <- 0
sentence$Incarceration.Months[is.na(sentence$Incarceration.Months)] <- 0
sentence$Incarceration.Years[is.na(sentence$Incarceration.Years)] <- 0
sentence$Incarceration.Tot <- 0
sentence$Incarceration.Tot <- (round(sentence$Incarceration.Days/30, 2)) + sentence$Incarceration.Months + (sentence$Incarceration.Years*12)
sentence$Incarceration.Trunc <- ifelse(sentence$Incarceration.Tot > 1200, 1200, sentence$Incarceration.Tot)
sentence$Incarceration.Trunc80 <- ifelse(sentence$Incarceration.Tot > 960, 960, sentence$Incarceration.Tot)
sentence$Incarceration.Trunc70 <- ifelse(sentence$Incarceration.Tot > 840, 840, sentence$Incarceration.Tot)
sentence$Incarceration.Trunc60 <- ifelse(sentence$Incarceration.Tot > 720, 720, sentence$Incarceration.Tot)
sentence$Incarceration.Trunc50 <- ifelse(sentence$Incarceration.Tot > 600, 600, sentence$Incarceration.Tot)


# Note: Assume a life sentence is equivalent to 100 years
sentence$Incarceration.Trunc[sentence$Incarceration.Type == "LIF"] <- 1200

## for probation
sentence$Probation.Tot <- NA
sentence$Probation.Days[is.na(sentence$Probation.Days)] <- 0
sentence$Probation.Months[is.na(sentence$Probation.Months)] <- 0
sentence$Probation.Years[is.na(sentence$Probation.Years)] <- 0

sentence$Probation.Tot <- 0
sentence$Probation.Tot <- (round(sentence$Probation.Days/30, 2)) + sentence$Probation.Months + (sentence$Probation.Years*12)
sentence$Probation.Trunc <- ifelse(sentence$Probation.Tot > 1200, 1200, sentence$Probation.Tot)


#################################################################
## Cleaning up FJC data to limit it only to variables used
#################################################################

fjc <- fjc[,c("nid","jid","Last.Name","First.Name","Middle.Name","Appointing.President..1.","Professional.Career","Committee.Action.Date..1.","Commission.Date..1.","Party.of.Appointing.President..1.","Termination.Date..1.","Gender","Race.or.Ethnicity","School..2.","Court.Type..1.","Court.Name..1.","imputed.dime.cfscore","jcs.score.dw","Priv.Criminal.Defense")]
fjc$Committee.Congress <- NA


# imputing the Congressional session:
for(i in 1:nrow(fjc)){
	if(ymd(fjc$Committee.Action.Date..1.[i]) > ymd("1929-01-01") & fjc$Committee.Action.Date..1.[i] != ""){
	fjc$Committee.Congress[i] <- senate$congress[ymd(fjc$Committee.Action.Date..1.[i]) %within% senate$interval]
	}
}


## Indicator for public defender (double checked by an RA)
fjc$pub.defender <- 0
fjc$pub.defender[grepl("defender", ignore.case = TRUE, fjc$Professional.Career)] <- 1
fjc$pub.defender[grepl("public defender", ignore.case = TRUE, fjc$Professional.Career)] <- 1
sum(fjc$pub.defender)

## Remove volunteer public defenders from being listed as PDs - this was done by having an RA go through all entries & they found two
fjc$pub.defender[fjc$Professional.Career == "Attorney, U.S. Department of Justice, 1952-1953; Volunteer defender, Philadelphia, Pennsylvania, 1953; Private practice, Philadelphia, Pennsylvania, 1953-1956, 1960-1967, 1973-2000; Instructor, Seton Hall University School of Law, 1953-1956; Assistant district attorney, Philadelphia, Pennsylvania, 1956; Deputy city solicitor, Philadelphia, Pennsylvania, 1956-1960"] <- 0

fjc$pub.defender[fjc$Professional.Career == "Law clerk, Hon. Cynthia Kinser, U.S. District Court for the Western District of Virginia, 1993-1994; Volunteer, Federal Defender Services, Greeneville, Tennessee, 1994-1995; Private practice, Morristown, Tennessee, 1995-1996; Private practice, Johnson City, Tennessee, 1996-2015"] <- 0

# Manually adding two who were revealed to have PD experience by RA coders: W. Allen Pepper Jr. (NID- 1390956) and Layn R. Phillips (NID- 1386306)
fjc$pub.defender[fjc$nid == 1390956] <- 1
fjc$pub.defender[fjc$nid == 1386306] <- 1

## Manually adding one person who was revealed to have private CD experience by RA coders: Candace Jackson Akiwumi 
fjc$Priv.Criminal.Defense[fjc$nid == 10300101] <- 1

## indicator for prosecutor
fjc$prosecutor <- 0
fjc$prosecutor[grepl("prosecutor", ignore.case = TRUE, fjc$Professional.Career)] <- 1
fjc$prosecutor[grepl("Attorney General", ignore.case = TRUE, fjc$Professional.Career)] <- 1
fjc$prosecutor[grepl("U.S. Attorney", ignore.case = TRUE, fjc$Professional.Career)] <- 1
fjc$prosecutor[grepl("Assistant U.S. Attorney", ignore.case = TRUE, fjc$Professional.Career)] <- 1
fjc$prosecutor[grepl("district attorney", ignore.case = TRUE, fjc$Professional.Career)] <- 1


## simplifying FJC race variable to white, black, or other (doing so ONLY following a reviewer recommendation to simplify racial categories)
fjc$Race.or.Ethnicity2 <- fjc$Race.or.Ethnicity
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "African American"] <- "African American"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Hispanic"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Hispanic/White"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "White"] <- "White"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Asian American"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Pakistani"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "American Indian"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "African American/American Indian"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "African American/Asian American"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "African American/White"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "African American/Hispanic"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Afro-Latino/Hispanic"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Asian American/Hispanic"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Asian American/White"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Asian American/Hispanic"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Pacific Islander/White"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Asian American/Pacific Islander"] <- "Other"
fjc$Race.or.Ethnicity2[fjc$Race.or.Ethnicity == "Chaldean"] <- "Other"


fjc$Race.or.Ethnicity2 <- factor(fjc$Race.or.Ethnicity2, levels = c("White","African American","Other"))
fjc$Race.or.Ethnicity <- fjc$Race.or.Ethnicity2
fjc$Race.or.Ethnicity2 <- NULL

## cleaning up comission year
fjc$Commission.Year..1. <- NULL
fjc$Commission.Year..1. <- substr(fjc$Commission.Date..1.,1,4)


# Note: We don't use this variable
fjc$Termination.Year..1. <- NULL
fjc$Termination.Year..1. <- substr(fjc$Termination.Date..1.,1,4)
fjc$Termination.Year..1.[fjc$Termination.Year..1. == ""] <- "2022"

fjc$Commission.Date..1. <- as.Date(fjc$Commission.Date..1., "%Y-%m-%d")

# subsetting district judges appointed post 1960 for use in Table 2:
recents <- subset(fjc, Commission.Year..1.> 1959)
recents <- subset(recents, Court.Type..1. == "U.S. District Court")


# judges who are both public defenders & prosecutors
mean(na.omit(recents$pub.defender == 1 & recents$prosecutor == 1))


#################################################################
## Table 2: Summary Statistics Table
#################################################################

dems <- subset(recents, Party.of.Appointing.President..1. == "Democratic")
reps <- subset(recents, Party.of.Appointing.President..1. == "Republican")


women <- cbind(mean(na.omit(recents$Gender == "Female")),mean(na.omit(dems$Gender == "Female")), mean(na.omit(reps$Gender == "Female")))
whites <- cbind(mean(na.omit(recents$Race.or.Ethnicity == "White")),mean(na.omit(dems$Race.or.Ethnicity == "White")), mean(na.omit(reps$Race.or.Ethnicity == "White")))
blacks <- cbind(mean(na.omit(recents$Race.or.Ethnicity == "African American")),mean(na.omit(dems$Race.or.Ethnicity == "African American")), mean(na.omit(reps$Race.or.Ethnicity == "African American")))
harv <- cbind(mean(na.omit(recents$School..2. == "Harvard Law School")),mean(na.omit(dems$School..2. == "Harvard Law School")), mean(na.omit(reps$School..2. == "Harvard Law School")))
yale <- cbind(mean(na.omit(recents$School..2. == "Yale Law School")),mean(na.omit(dems$School..2. == "Yale Law School")), mean(na.omit(reps$School..2. == "Yale Law School")))
pub <- cbind(mean(na.omit(recents$pub.defender)),mean(na.omit(dems$pub.defender)), mean(na.omit(reps$pub.defender)))
pros <- cbind(mean(na.omit(recents$prosecutor)),mean(na.omit(dems$prosecutor)), mean(na.omit(reps$prosecutor)))
privates <- cbind(mean(na.omit(recents$Priv.Criminal.Defense == 1)),mean(na.omit(dems$Priv.Criminal.Defense == 1)), mean(na.omit(reps$Priv.Criminal.Defense == 1)))


table.2 <- round(100*rbind(women, whites, blacks, pub, pros, privates, c(nrow(recents)/100, nrow(dems)/100, nrow(reps)/100)),1)
rownames(table.2) <- c("% Women", "% White","% Black", "% Public Defender", "% Prosecutor", "% Private Criminal Defense Experience (Some)", "Number")
colnames(table.2) <- c("All", "Democrats", "Republicans")
tab2 <- xtable(table.2, caption = "Characteristics of U.S. District Court judges appointed since 1960. Source: Federal Judicial Center.", label = "t:judge")

tab2

#################################################################
## Figure of the % of prosecutors/public defenders over time (not in paper)
#################################################################

djs <- subset(careers, careers$Court.Type == "U.S. District Court")
djs <- merge(djs, fjc, by.x = "nid", by.y = "nid", all.x = TRUE, all.y = FALSE)


djs$Commission.Year..1. <- NULL
djs$Commission.Year..1. <- substr(djs$Commission.Date..1.,1,4)

# only for purposes of this plot
djs$Termination.Year..1. <- NULL
djs$Termination.Year..1. <- substr(djs$Termination.Date..1.,1,4)
djs$Termination.Year..1.[djs$Termination.Year..1. == ""] <- "2022"

djs$Commission.Date..1. <- as.Date(djs$Commission.Date..1., "%Y-%m-%d")


holder <- matrix(data = NA, ncol = 3, nrow = length(1900:2022))
holder[,1] <- 1900:2022
for(i in 1:nrow(holder)){
	meg <- djs[djs$Commission.Year..1. <= holder[i,1] & djs$Termination.Year..1. >= holder[i,1],]
	holder[i,2] <- mean(na.omit(meg$pub.defender))
	holder[i,3] <- mean(na.omit(meg$prosecutor))
}

holder <- data.frame(holder)
	
figure1 <- ggplot(holder, aes(x=X1)) +
	geom_line(aes(y = X2, colour="Public Defenders")) + 
	geom_line(aes(y = X3, colour="Prosecutors")) + 
	ylim(0, .50) +
	xlab("Year") +
	ylab("Proportion") +
	ggtitle("Proportion of Federal District Judges With Criminal Justice Experience") +
	scale_color_manual(name = "", values = c("Prosecutors" = "#CC0000","Public Defenders" = "#000099"))
	
figure1

#################################################################
## Important notes re: merging TRAC data
#################################################################

## the only judge information in the TRAC substantive files is contained in the 
## extract.csv file, although we do not otherwise use that data
## we merge as follows:
## 1. the "Judge.Id" in the extract.csv file matches the "jdgid" var in the history.csv file
## 2. the "fjc_id" var in the history.csv file matches the "jid" id in the FJC data
## 3. "jid" is being discontinued by the FJC, so use "nid" moving forward

## for example, all of these should be Alfred V. Covello (per the extract file)
head(extract$Judge[extract$Judge.Id == "00250"])
history$judge_lastname[history$jdgid == 00250]
history$fjc_id[history$jdgid == 00250]
fjc$Last.Name[fjc$jid == 517]

## Note that FJC is using "niid"

judges <- data.frame(extract$Case.ID, extract$District.Code, extract$Judge.Id, extract$Judge)
colnames(judges) <- c("Case.ID", "District","Judge.Id", "Judge")
judges <- subset(judges, Judge != "Unknown")
judges <- unique(judges)
head(judges)


#################################################################
## Merging on the entirety of the charging data
#################################################################

charge$Year <- substr(charge$Disposition.Date,6,9)
charge$Month <- substr(charge$Disposition.Date,3,5)

## Limiting charges to those from 2010-2019
charge <- subset(charge, Year %in% 2010:2019)

## merging with sentences
charge.sentence <- merge(charge, sentence, by.x = c("Case.Id","District", "Participant.Id"), by.y = c("caseid","distcode", "partid"), all.x = TRUE)

## and then to judges
charge.sentence <- merge(charge.sentence, judges, by.x = c("Case.Id","District"), by.y = c("Case.ID","District"), all.x = TRUE)
charge.sentence$Judge.Id <- as.numeric(charge.sentence$Judge.Id)

## and then to FJC data
apollo <- merge(charge.sentence, history, by.x = "Judge.Id", by.y = "jdgid", all.x = TRUE)
apollo <- merge(apollo, fjc, by.x = "fjc_id", by.y = "jid", all.x = TRUE)

## Merged data is called "apollo"

## cleaning up:
names(apollo)[names(apollo) == "District.x"] <- "District"
names(apollo)[names(apollo) == "Appointing.President..1."] <- "President"
colnames(apollo)[which(names(apollo) == "Case.Id")] <- "Case"
colnames(apollo)[which(names(apollo) == "Participant.Id")] <- "Participant"

#################################################################
## Looking at Types of Punishments 
#################################################################

apollo$any.probation <- 0
apollo$any.incarceration <- 0
apollo$any.fine <- 0

# indicator for any probation reported:
apollo$any.probation[apollo$Probation.Days !=0|apollo$Probation.Months !=0|apollo$Probation.Years !=0] <- 1

# indicator for any incarceration reported:
apollo$any.incarceration[apollo$Incarceration.Days|apollo$Incarceration.Months|apollo$Incarceration.Years] <- 1
cbind(apollo$any.incarceration, apollo$Incarceration.Days, apollo$Incarceration.Months, apollo$Incarceration.Years)

# indicator for any fines reported:
apollo$any.fine[apollo$Amount.of.Fine !=""] <- 1



apollo$punishment <- NA
apollo$punishment[apollo$any.probation == 1 & apollo$any.incarceration == 0 & apollo$any.fine == 0] <- "Probation"
apollo$punishment[apollo$any.probation == 0 & apollo$any.incarceration == 1 & apollo$any.fine == 0] <- "Incarceration"
apollo$punishment[apollo$any.probation == 0 & apollo$any.incarceration == 0 & apollo$any.fine == 1] <- "Fine"

apollo$punishment[apollo$any.probation == 1 & apollo$any.incarceration == 1 & apollo$any.fine == 0] <- "Probation/Incarceration"
apollo$punishment[apollo$any.probation == 0 & apollo$any.incarceration == 1 & apollo$any.fine == 1] <- "Fine/Incarceration"
apollo$punishment[apollo$any.probation == 1 & apollo$any.incarceration == 0 & apollo$any.fine == 1] <- "Fine/Probation"

levels(apollo$punishment) <- c("Incarceration","Fine", "Probation", "Fine/Incarceration","Probation/Incarceration","Fine/Probation")
table(apollo$punishment)


#################################################################
## Subsetting Charging Data
#################################################################

## subsetting only to instances with an identified district judge (last name reported)
apollo <- subset(apollo, !is.na(Last.Name))
dim(apollo)
length(unique(apollo$nid))

## Subseting to reporting on incarceration at all (including 0)
apollo <- subset(apollo, Incarceration.Tot >=0)

## Notes: 
## Above removes about 775k cases with no sentencing information included at all (not even 0)
## This is a small amount relative to the size of the dataset
## Does not change results as these would be dropped from regressions, but including information on some characteristics of these.
## 25% (compared with 40% of cases with sentencing information) have guilty pleas. But these mostly seem like post-sentencing criminal forfeiture proceedings as 80% of these guilties have a forfeiture-related disposition reason

###########
## all sentences
###########

# Drop redundant charges/dispositions because the sentencing data 
# is unique to the case/participant. subsetting like this chooses arbitrary 
# disposition types and reasons, so we drop those variables for safety.  

u.names <- rownames(unique(apollo[, c("Case", "Participant")]))
allsentences <- apollo[u.names,]
#allsentences$Disposition.Type <- NULL
#allsentences$Disposition.Reason <- NULL
dim(allsentences)


###########
## all trials (bench and jury)
###########

alltrials <- subset(apollo, Disposition.Reason == "BTRD"|Disposition.Reason == "JTRD")
u.names <- rownames(unique(alltrials[, c("Case", "Participant")]))
alltrials <- alltrials[u.names,]
dim(alltrials)

###########
## all pleas
###########

allpleas <- subset(apollo, Disposition.Reason == "PLED")
u.names <- rownames(unique(allpleas[, c("Case", "Participant")]))
allpleas <- allpleas[u.names,]
dim(allpleas)

###########
## all charges with a guilty disposition
###########

allguilties <- subset(apollo, Disposition.Type == "GT")
u.names <- rownames(unique(allguilties[, c("Case", "Participant")]))
allguilties <- allguilties[u.names,]
dim(allguilties)


###########
## all trials with a guilty disposition
###########

guiltyverdicts <- subset(allguilties, Disposition.Reason == "BTRD"|Disposition.Reason == "JTRD")
u.names <- rownames(unique(guiltyverdicts[, c("Case", "Participant")]))
guiltyverdicts <- guiltyverdicts[u.names,]
dim(guiltyverdicts)


###########
## all pleas with a guilty disposition
###########

pled <- subset(allguilties, Disposition.Reason == "PLED")
u.names <- rownames(unique(pled[, c("Case", "Participant")]))
pled <- pled[u.names,]
dim(pled)


#################################################################
# summary statistics table for data discussion
#################################################################

row1 <- cbind(nrow(allguilties)/nrow(allsentences), nrow(pled)/nrow(allpleas), nrow(guiltyverdicts)/nrow(alltrials))

row2 <- cbind(mean(na.omit(allsentences$Incarceration.Tot > 0)), mean(na.omit(allpleas$Incarceration.Tot > 0)), mean(na.omit(alltrials$Incarceration.Tot > 0)))

row3 <- cbind(mean(na.omit(allsentences$Community.Service.Hours !="")), mean(na.omit(allpleas$Community.Service.Hours !="")), mean(na.omit(alltrials$Community.Service.Hours !="")))

row4 <- cbind(mean(na.omit(allsentences$Probation.Tot >0)), mean(na.omit(allpleas$Probation.Tot >0)), mean(na.omit(alltrials$Probation.Tot >0)))


row5 <- cbind(nrow(allsentences), nrow(allpleas), nrow(alltrials))

## table 1:

tab1 <- rbind(row1*100, row2*100, row3*100, row4*100, row5)
colnames(tab1) <- c("All Charges", "All Pleas", "All Trials")
rownames(tab1) <- c("% Guilty", "% Any Incarceration","% Any Community Service","% Any Probation","N")


tab1 <- xtable(tab1, caption = "Summary statistics on unique federal charges (among those assigned to a federal district or appeals judge only).", label = "t:tab2")

tab1

#################################################################
## Model covariate names for input into ModelSummary function
#################################################################

aa = c("pub.defender"="Former Pub Defender", "years.pd" = "Years of PD Experience", "Case" = "Case","Participant" = "Defendant","prosecutor"="Former Prosecutor", `I(Gender == "Female")TRUE` = "Female Judge", `as.factor(Race.or.Ethnicity)African American` = "African American Judge", `as.factor(Race.or.Ethnicity)Hispanic` = "Hispanic", `as.factor(Race.or.Ethnicity)Asian American` = "Asian American", `as.factor(Race.or.Ethnicity)American Indian` = "American Indian", `as.factor(Race.or.Ethnicity)Two or more` = "Two or More Races/Ethnicities", `as.numeric(Commission.Year..1.)` = "Judge Commission Year", `I(chg_type == "F")TRUE` = "Charge is a Felony", `I(Race.or.Ethnicity == "African American")TRUE` = "Black", `pub.defender:I(Gender == "Female")TRUE` = "Pub Defender * Female", `pub.defender:I(Race.or.Ethnicity == "African American")TRUE` = "Pub Defender * Black", `Party.of.Appointing.President..1.Republican` = "Republican", `pub.defender:Party.of.Appointing.President..1.Republican` = "Pub Defender * Republican", `prosecutor:Party.of.Appointing.President..1.Republican` = "Prosecutor * Republican", "as.factor(Year)" = "Year", "PresidentDonald J. Trump"="Trump Appointee", "PresidentJohn F. Kennedy"="Kennedy Appointee", "PresidentGeorge W. Bush"="Bush II Appointee","PresidentGeorge H.W. Bush"="Bush I Appointee","PresidentJimmy Carter"="Carter Appointee","PresidentRichard M. Nixon"="Nixon Appointee","PresidentLyndon B. Johnson"="Johnson Appointee","PresidentGerald Ford"="Ford Appointee","PresidentRonald Reagan"="Reagan Appointee","PresidentWilliam J. Clinton"="Clinton Appointee","PresidentBarack Obama"="Obama Appointee", "imputed.dime.cfscore" = "Judge DIME Score (Imputed)", "as.factor(Race.or.Ethnicity)Other" = "Judge Race Other", "jcs.score.dw" = "Judge JCS Score (Senate DW-NOMINATE)", "I(Priv.Criminal.Defense == 1)TRUE" = "Private Criminal Defense Experience", "pub.defender:PresidentGeorge H.W. Bush" = "Pub Defender * Bush I", "pub.defender:PresidentGeorge W. Bush" = "Pub Defender * Bush II","pub.defender:PresidentJimmy Carter" = "Pub Defender * Carter","pub.defender:PresidentRonald Reagan" = "Pub Defender * Reagan","pub.defender:PresidentWilliam J. Clinton" = "Pub Defender * Clinton")

bb <- c("AIC","BIC","R2 Adj.")

gof_omit = "Std*"


#################################################################
## Analyses
#################################################################


###########
## any incarceration:
###########

my.fe1a <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = alltrials)
my.fe1a <- summary(my.fe1a, cluster = ~Case + Participant)
my.fe1a


my.fe2a <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = allpleas)
my.fe2a <- summary(my.fe2a, cluster = ~Case + Participant)
my.fe2a


 my.fe3a <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F")+ President| District + Month + Year, data = allsentences)
 my.fe3a <- summary(my.fe3a, cluster = ~Case + Participant)
 my.fe3a

my.fe3a_DIME <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F") + imputed.dime.cfscore+President| District + Month + Year, data = allsentences)
my.fe3a_DIME <- summary(my.fe3a_DIME, cluster = ~Case + Participant)
my.fe3a_DIME

cc <- modelsummary(models = list("Jury or Bench Trial" = my.fe1a, "Pled" = my.fe2a, "All Charges" = my.fe3a, "All Charges" = my.fe3a_DIME), stars = TRUE, integer = 5, output = "tab3a.tex", threeparttable = TRUE, title = 'Outcome is whether sentence (if any) included any incarceration. All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:any}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")



my.fe1 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President| District + Month + Year, data = guiltyverdicts)
my.fe1 <- summary(my.fe1, cluster = ~Case + Participant)
my.fe1

my.fe2 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President| District + Month + Year, data = pled)
my.fe2 <- summary(my.fe2, cluster = ~Case + Participant)
my.fe2


my.fe3 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F") + President| District + Month + Year, data = allguilties)
my.fe3 <- summary(my.fe3, cluster = ~Case + Participant)
my.fe3


cc <- modelsummary(models = list("Jury or Bench Trial" = my.fe1, "Pled" = my.fe2, "All Guilty" = my.fe3), stars = TRUE, integer = 5, output = "tab3.tex", threeparttable = TRUE, title = 'Analyses for charges that result in a guilty disposition only. Outcome is whether sentence (if any) included any incarceration. All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:any_guilty}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

cc

###########
# community service/probation
###########

my.fe4 <- feols(I(Community.Service.Hours !="" & Incarceration.Tot == 0 & Probation.Tot == 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District  + Month + Year, data = allsentences)
my.fe4 <- summary(my.fe4, cluster = ~Case + Participant)
my.fe4


my.fe5 <- feols(I((Community.Service.Hours !=""|Probation.Tot >= 0) & Incarceration.Tot == 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = allsentences)
my.fe5 <- summary(my.fe5, cluster = ~Case + Participant)
my.fe5


my.fe5b <- feols(I(Community.Service.Hours !="" & Probation.Tot >= 0 & Incarceration.Tot == 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = allsentences)
my.fe5b <- summary(my.fe5b, cluster = ~Case + Participant)
my.fe5b

cc <- modelsummary(models = list("Comm. Service Only" = my.fe4, "Comm. Service or Probation" = my.fe5, "Comm. Service and Probation" = my.fe5b), stars = TRUE, output = "tab4.tex", threeparttable = TRUE, integer = 5, title = 'Outcome is no incarceration, but community service only (Column 1), community service or probation only (Column 2), and community service and probation only (Column 3). All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:community}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

#### Table 14 in the Appendix

cc

############
# incarcerationlength
###########

my.fe6a <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = alltrials)
my.fe6a <- summary(my.fe6a, cluster = ~Case + Participant)
my.fe6a

my.fe6a_DIME <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + imputed.dime.cfscore + President| District + Month + Year, data = alltrials)
my.fe6a_DIME <- summary(my.fe6a_DIME, cluster = ~Case + Participant)
my.fe6a_DIME

my.fe7a <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = allpleas)
my.fe7a <- summary(my.fe7a, cluster = ~Case + Participant)
my.fe7a


my.fe8a <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President | District + Month + Year, data = allsentences)
my.fe8a <- summary(my.fe8a, cluster = ~Case + Participant)
my.fe8a

my.fe8a_DIME <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + imputed.dime.cfscore+ President| District + Month + Year, data = allsentences)
my.fe8a_DIME <- summary(my.fe8a_DIME, cluster = ~Case + Participant)
my.fe8a_DIME

table4 <- modelsummary(models = list("Jury or Bench Trial" = my.fe6a, "Pled" = my.fe7a, "All Charges" = my.fe8a), stars = TRUE, output = "tab5a.tex", integer = 2, threeparttable = TRUE, title = 'Outcome is incarceration length truncated at 100 years (1200 months). Sentences exceeding 100 years are coded as 100 years. All models are OLS and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:length}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

#### Table 4 in the main text

table4

## conditioning on guilt

# guilty verdicts (OLS)
my.fe6 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = guiltyverdicts)
my.fe6 <- summary(my.fe6, cluster = ~Case + Participant)
my.fe6

# guilty pleas (OLS)
my.fe7 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = pled)
my.fe7 <- summary(my.fe7, cluster = ~Case + Participant)
my.fe7


# among all guilties (LPM)
my.fe8 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F") + President| District + Month + Year, data = allguilties)
my.fe8 <- summary(my.fe8, cluster = ~Case + Participant)
my.fe8


cc <- modelsummary(models = list("Incarceration Among Guilty" = my.fe8, "Incarceration Length Among Guilty Trials" = my.fe6), stars = TRUE, integer = 5, output = "tab-guilties.tex", threeparttable = TRUE, title = 'Analyses for charges that result in a guilty disposition only. Outcome is whether sentence (if any) included any incarceration (Column 1, linear probability model) and incarcetation length (Column 2, OLS). All models include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:guilties}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

#### Table 8 in the Appendix

cc


###########
# incarceration length - life yes/no
###########

my.fe9a <- feols(I(Incarceration.Trunc >= (12*100)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = alltrials)
my.fe9a <- summary(my.fe9a, cluster = ~Case + Participant)
my.fe9a

my.fe10a <- feols(I(Incarceration.Trunc >= (12*70)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = alltrials)
my.fe10a <- summary(my.fe10a, cluster = ~Case + Participant)
my.fe10a


my.fe11a <- feols(I(Incarceration.Trunc >= 12*30) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = alltrials)
my.fe11a <- summary(my.fe11a, cluster = ~Case + Participant)
my.fe11a



# back of the envelope calculation:
# 8% public defenders:
1*((mean(predict(my.fe11a))-coef(my.fe11a)[1]) * nrow(alltrials))
0.92 *((mean(predict(my.fe11a))-coef(my.fe11a)[1])*nrow(alltrials)) + .08 * (mean(predict(my.fe11a)+coef(my.fe11a)[1])*nrow(alltrials))

# 35%  public defenders:
1*((mean(predict(my.fe11a))-coef(my.fe11a)[1]) * nrow(alltrials))
0.65 *((mean(predict(my.fe11a))-coef(my.fe11a)[1])*nrow(alltrials)) + .35 * (mean(predict(my.fe11a)+coef(my.fe11a)[1])*nrow(alltrials))

cc <- modelsummary(models = list("More than 100 Years" = my.fe9a, "More than 70 Years" = my.fe10a, "More than 30 Years" = my.fe11a), stars = TRUE, output = "tab8a.tex", integer = 2, threeparttable = TRUE, title = 'Outcome is incarceration length being greater than some length (yes or no). All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:trunclength}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

#### Table 5 in the Main Text
cc


my.fe9 <- feols(I(Incarceration.Trunc >= (12*100)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = guiltyverdicts)
my.fe9 <- summary(my.fe9, cluster = ~Case + Participant)
my.fe9

my.fe10 <- feols(I(Incarceration.Trunc >= (12*70)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = guiltyverdicts)
my.fe10 <- summary(my.fe10, cluster = ~Case + Participant)
my.fe10


my.fe11 <- feols(I(Incarceration.Trunc >= 12*30) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President| District + Month + Year, data = guiltyverdicts)
my.fe11 <- summary(my.fe11, cluster = ~Case + Participant)
my.fe11

cc <- modelsummary(models = list("More than 100 Years" = my.fe9, "More than 70 Years" = my.fe10, "More than 30 Years" = my.fe11), stars = TRUE, output = "tab8.tex", integer = 2, threeparttable = TRUE, title = 'Analyses for charges that result in a guilty disposition only. Outcome is incarceration length being greater than some length (yes or no). All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:trunclength_guilty}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")


#### Table 9 in the Appendix
cc


#################################################################
## Addiional Appendix Analyses
#################################################################

###########
## Figure 1
###########

plot(density(alltrials$Incarceration.Trunc), main = "Verdicts Only", xlab = "Incarceration in Months (Truncated at 100 Years)", ylab = "", lwd = 2)
lines(density(alltrials$Incarceration.Trunc[alltrials$prosecutor == 1]), col = "#CC0000", lwd = 2)
lines(density(alltrials$Incarceration.Trunc[alltrials$pub.defender == 1]), col = "#000099", lwd = 2)
legend("topright", legend=c("All","Prosecutors", "Public Defenders"),
       col=c("black","#CC0000", "#000099"), lty=1:1, cex=0.8, bty="n")


plot(density(allpleas$Incarceration.Trunc), main = "Pleas Only", xlab = "Incarceration in Months (Truncated at 100 Years)", ylab = "", lwd = 2)
lines(density(allpleas$Incarceration.Trunc[allpleas$prosecutor == 1]), col = "#CC0000", lwd = 2)
lines(density(allpleas$Incarceration.Trunc[allpleas $pub.defender == 1]), col = "#000099", lwd = 2)
legend("topright", legend=c("All","Prosecutors", "Public Defenders"),
       col=c("black","#CC0000", "#000099"), lty=1:1, cex=0.8, bty="n")

###########
## outcomes
###########

my.fe12 <- feols(I(Disposition.Reason == "BTRD") ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F") + President| District + Month + Year, data = allsentences)
my.fe12 <- summary(my.fe12, ~ Case + Participant)
my.fe12

my.fe13 <- feols(I(Disposition.Reason == "PLED"|Disposition.Reason == "PLEA") ~ pub.defender + I(Priv.Criminal.Defense == 1) + prosecutor + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F") + President| District + Month + Year, data = allsentences)
my.fe13 <- summary(my.fe13, ~ Case + Participant)
my.fe13

cc <- modelsummary(models = list("Jury or Bench Trial" = my.fe12, "Pled" = my.fe13), stars = TRUE, threeparttable = TRUE, 
output = "tab9.tex", integer = 5, title = 'Outcome is whether any charge, regardless of guilt or procedural posture that could be influenced by public defender status, proceeded to a jury or bench trial (Column 1), or was pled (Column 2). All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level. \\label{t:outcomes}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")

#### Table 7 in the Appendix

cc

############
# interactions
###########

# on party (not in paper)

my.fe15a <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = alltrials)
my.fe15a <- summary(my.fe15a, cluster = ~Case + Participant)
my.fe15a

my.fe16a <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = allpleas)
my.fe16a <- summary(my.fe16a, cluster = ~Case + Participant)
my.fe16a


my.fe17a <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F")| District + Month + Year, data = allsentences)
my.fe17a <- summary(my.fe17a, cluster = ~Case + Participant)
my.fe17a

# but no sig on interaction with party
my.fe18a <- feols(Incarceration.Trunc ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = alltrials)
my.fe18a <- summary(my.fe18a, cluster = ~Case + Participant)
my.fe18a


cc <- modelsummary(models = list("Any Incarceration (Trials)" = my.fe15a, "Any Incarceration (Pleas)" = my.fe16a, "Any Incarceration (All)" = my.fe17a, "Incarceration Length" = my.fe18a), stars = TRUE, integer = 5, output = "tab10a.tex", threeparttable = TRUE, title = 'For Columns 1-3, outcome is whether sentence (if any) included  any incarceration. Models are linear probability models and include fixed effects for district, month, and year. For Column 4, outcome is truncated sentence length for sentences with jury or bench trials. For all models, standard errors clustered at the case and defendant level.\\label{t:party}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

cc

# not in paper


my.fe15 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = guiltyverdicts)
my.fe15 <- summary(my.fe15, cluster = ~Case + Participant)
my.fe15

my.fe16 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = pled)
my.fe16 <- summary(my.fe16, cluster = ~Case + Participant)
my.fe16


my.fe17 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F")| District + Month + Year, data = allguilties)
my.fe17 <- summary(my.fe17, cluster = ~Case + Participant)
my.fe17

# but no sig on interaction with party
my.fe18 <- feols(Incarceration.Trunc ~ pub.defender*Party.of.Appointing.President..1. + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = alltrials)
my.fe18 <- summary(my.fe18, cluster = ~Case + Participant)
my.fe18

cc <- modelsummary(models = list("Any Incarceration (Trials)" = my.fe15, "Any Incarceration (Pleas)" = my.fe16, "Any Incarceration (All)" = my.fe17, "Incarceration Length" = my.fe18), stars = TRUE, integer = 5, output = "tab10.tex", threeparttable = TRUE, title = 'For Columns 1-3, outcome is whether sentence (if any) included  any incarceration. Models are linear probability models and include fixed effects for district, month, and year. For Column 4, outcome is truncated sentence length for sentences with jury or bench trials. For all models, standard errors clustered at the case and defendant level.\\label{t:party}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")


cc

###########
# on race (Black)
###########

my.fe19 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Race.or.Ethnicity == "African American") + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = alltrials)
my.fe19 <- summary(my.fe19, cluster = ~Case + Participant)
my.fe19

my.fe20 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Race.or.Ethnicity == "African American") + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = allpleas)
my.fe20 <- summary(my.fe20, cluster = ~Case + Participant)
my.fe20


#Previous version of this table, missing private criminal defense experience
#my.fe21 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Race.or.Ethnicity == "African American") + prosecutor + I(Gender == "Female") + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = allsentences)
#my.fe21 <- summary(my.fe21, cluster = ~Case + Participant)
#my.fe21


#This one currently included in the manuscript
my.fe21 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Race.or.Ethnicity == "African American") + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = allsentences)
my.fe21 <- summary(my.fe21, cluster = ~Case + Participant)
my.fe21


my.fe22 <- feols(Incarceration.Trunc ~ pub.defender*I(Race.or.Ethnicity == "African American") + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = alltrials)
my.fe22 <- summary(my.fe22, cluster = ~Case + Participant)
my.fe22


cc <- modelsummary(models = list("Any Incarceration (Trials)" = my.fe19, "Any Incarceration (Pleas)" = my.fe20, "Any Incarceration (All)"= my.fe21, "Incarceration Length" = my.fe22), stars = TRUE, integer = 5, output = "tab11.tex", threeparttable = TRUE, title = 'For Columns 1-3, outcome is whether sentence (if any) included  any incarceration. Models are linear probability models and include fixed effects for district, month, year, and identity of appointing president interacted with public defender. For Column 4, outcome is truncated sentence length for sentences with jury or bench trials. For all models, standard errors clustered at the case and defendant level.\\label{t:race}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")


#### Table 10 in the Appendix

cc

###########
# on gender (Female)
###########

my.fe23 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Gender == "Female") + prosecutor + I(Priv.Criminal.Defense == 1) + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = alltrials)
my.fe23 <- summary(my.fe23, cluster = ~Case + Participant)
my.fe23


my.fe24 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Gender == "Female") + prosecutor + I(Priv.Criminal.Defense == 1) + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = allpleas)
my.fe24 <- summary(my.fe24, cluster = ~Case + Participant)
my.fe24


my.fe25 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*I(Gender == "Female") + prosecutor + I(Priv.Criminal.Defense == 1) + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = allsentences)
my.fe25 <- summary(my.fe25, cluster = ~Case + Participant)
my.fe25


my.fe26 <- feols(Incarceration.Trunc ~ pub.defender*I(Gender == "Female") + prosecutor + I(Priv.Criminal.Defense == 1) + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")  + President|  District + Month + Year, data = alltrials)
my.fe26 <- summary(my.fe26, cluster = ~Case + Participant)
my.fe26


## Table 11
table11 <- modelsummary(models = list("Any Incarceration (Trials)" = my.fe23, "Any Incarceration (Pleas)" = my.fe24, "Any Incarceration (All)" = my.fe25, "Incarceration Length" = my.fe26), stars = TRUE, integer = 5, output = "tab12.tex", threeparttable = TRUE, title = 'For Columns 1-3, outcome is whether sentence (if any) included  any incarceration. Models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. For Column 4, outcome is truncated sentence length for sentences with jury or bench trials. For all models, standard errors clustered at the case and defendant level.\\label{t:gender}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

#### Table 11 in the Appendix

table11

###########
# on IDENTITY of appointing president (not just party) (suggested by a JOP Reviewer)
###########

my.fe27 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*President + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = guiltyverdicts)
my.fe27 <- summary(my.fe27, cluster = ~Case + Participant)
my.fe27

my.fe28 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*President + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = pled)
my.fe28 <- summary(my.fe28, cluster = ~Case + Participant)
my.fe28


my.fe29 <- feols(I(Incarceration.Tot > 0) ~ pub.defender*President + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + I(chg_type == "F")| District + Month + Year, data = allguilties)
my.fe29 <- summary(my.fe29, cluster = ~Case + Participant)
my.fe29


my.fe30 <- feols(Incarceration.Trunc ~ pub.defender*President + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") | District + Month + Year, data = alltrials)
my.fe30 <- summary(my.fe30, cluster = ~Case + Participant)
my.fe30


table12 <- modelsummary(models = list("Any Incarceration (Trials)" = my.fe27, "Any Incarceration (Pleas)" = my.fe28, "Any Incarceration (All)" = my.fe29, "Incarceration Length" = my.fe30), stars = TRUE, integer = 5, output = "tab-pres-interact.tex", threeparttable = TRUE, title = 'For Columns 1-3, outcome is whether sentence (if any) included  any incarceration. Models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. For Column 4, outcome is truncated sentence length for sentences with jury or bench trials. For all models, standard errors clustered at the case and defendant level.\\label{t:presidentID}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

#### Table 12 in the Appendix

table12



############
# subsetting to only clearly reported felonies (suggested by a commenter in a talk, as well as by reviewers)
###########

my.fe27 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = subset(allsentences, chg_type == "F"))
my.fe27 <- summary(my.fe27, cluster = ~Case + Participant)
my.fe27

my.fe28 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = subset(alltrials, chg_type == "F"))
my.fe28 <- summary(my.fe28, cluster = ~Case + Participant)
my.fe28


my.fe29 <- feols(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = subset(alltrials, chg_type == "F"))
my.fe29 <- summary(my.fe29, cluster = ~Case + Participant)
my.fe29

table15 <- modelsummary(models = list("Any Incarceration (All)" = my.fe27, "Incarceration Length (Trials)" = my.fe28, "Incarceration Length More than 30 Years (Trials)" = my.fe29), stars = TRUE, integer = 5, output = "tab13.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president. \\label{t:felonies}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")


#### Table 15 in the Appendix

table15

############
# including an FE for congress term (suggested by a prominent scholar in the field of sentencing)
############


my.fe30 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")| District + Committee.Congress + Month + Year, data = allsentences)
my.fe30 <- summary(my.fe30, cluster = ~Case + Participant)
my.fe30

my.fe31 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")| District + Committee.Congress + Month + Year, data = alltrials)
my.fe31 <- summary(my.fe31, cluster = ~Case + Participant)
my.fe31


my.fe32 <- feols(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F")| District + Committee.Congress + Month + Year, data = alltrials)
my.fe32 <- summary(my.fe32, cluster = ~Case + Participant)
my.fe32


table16 <- modelsummary(models = list("Any Incarceration (All)" = my.fe30, "Incarceration Length (Trials)" = my.fe31, "Incarceration Length More than 30 Years (Trials)" = my.fe32), stars = TRUE, integer = 5, output = "tab15.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:congsession}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")


#### Table 16 in the Appendix

table16

############
# looking at years spent as PD (suggested by reviewers)
############

allsentences <- merge(allsentences, RA, by.x = "nid", by.y = "nid", all.x = TRUE, all.y = FALSE)
alltrials <- merge(alltrials, RA, by.x = "nid", by.y = "nid", all.x = TRUE, all.y = FALSE)

allsentences$years.pd[is.na(allsentences$years.pd)] <- 0
alltrials$years.pd[is.na(alltrials$years.pd)] <- 0

my.fe33 <- feols(I(Incarceration.Tot > 0) ~ years.pd + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President|  District + Month + Year, data = allsentences)
my.fe33 <- summary(my.fe33, cluster = ~Case + Participant)
my.fe33

my.fe34 <- feols(Incarceration.Trunc ~ years.pd + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President|  District + Month + Year, data = alltrials)
my.fe34 <- summary(my.fe34, cluster = ~Case + Participant)
my.fe34


my.fe35 <- feols(I(Incarceration.Trunc > (30*12)) ~ years.pd + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President|  District + Month + Year, data = alltrials)
my.fe35 <- summary(my.fe35, cluster = ~Case + Participant)
my.fe35

table6 <- modelsummary(models = list("Any Incarceration (All)" = my.fe33, "Incarceration Length (Trials)" = my.fe34, "Incarceration Length More than 30 Years (Trials)" = my.fe35), stars = TRUE, integer = 5, output = "tab16.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:yearsexperience}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

#### Table 6 in the Main Text

table6 


##############
## robusntess of truncation
############


my.fe37 <- feols(Incarceration.Trunc80 ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = alltrials)
my.fe37 <- summary(my.fe37, cluster = ~Case + Participant)
my.fe37

my.fe38 <- feols(Incarceration.Trunc70 ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = alltrials)
my.fe38 <- summary(my.fe38, cluster = ~Case + Participant)
my.fe38

my.fe39 <- feols(Incarceration.Trunc60 ~ pub.defender + prosecutor  + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = alltrials)
my.fe39 <- summary(my.fe39, cluster = ~Case + Participant)
my.fe39

my.fe40 <- feols(Incarceration.Trunc50 ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.)  + President|  District + Month + Year, data = alltrials)
my.fe40 <- summary(my.fe40, cluster = ~Case + Participant)
my.fe40


table13 <-  modelsummary(models = list("80 Years" = my.fe37, "70 Years" = my.fe38, "60 Years" = my.fe39, "50 Years" = my.fe40), stars = TRUE, integer = 5, output = "tab7.tex", threeparttable = TRUE, title = 'Outcome is sentence length truncated at different years. For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:truncrobust}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

#### Table 13 in the Appendix

table13


########################
## JOP Table 3
########################


table3 <- modelsummary(models = list("Trials" = my.fe1a, "Pled" = my.fe2a, "All Charges" = my.fe3a, "All Charges" = my.fe3a_DIME, "All Charges" = my.fe17a), stars = TRUE, integer = 5, output = "JOP-tab3a.tex", threeparttable = TRUE, title = 'Outcome is whether sentence (if any) included any incarceration. All models are linear probability models and include fixed effects for district, month, year, and identity of appointing president. Standard errors clustered at the case and defendant level.\\label{t:any}', coef_rename = aa, gof_omit = "IC|Adj|Pseudo|Within")


### Table 3 in the Main Text

table3


############
# including DIME scores
############


my.fe41 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + imputed.dime.cfscore + President | District  + Month + Year, data = allsentences)
my.fe41 <- summary(my.fe41, cluster = ~Case + Participant)
my.fe41

my.fe42 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + imputed.dime.cfscore + President| District  + Month + Year, data = alltrials)
my.fe42 <- summary(my.fe42, cluster = ~Case + Participant)
my.fe42


my.fe43 <- feols(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + imputed.dime.cfscore + President| District + Month + Year, data = alltrials)
my.fe43 <- summary(my.fe43, cluster = ~Case + Participant)
my.fe43

table17 <- modelsummary(models = list("Any Incarceration (All)" = my.fe41, "Incarceration Length (Trials)" = my.fe42, "Incarceration Length More than 30 Years (Trials)" = my.fe43), stars = TRUE, integer = 5, output = "tabDIMEa.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:DIME}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

### Table 17 in the Appendix

table17


############
# including JCS scores
############

my.fe44 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + jcs.score.dw + President | District  + Month + Year, data = allsentences)
my.fe44 <- summary(my.fe44, cluster = ~Case + Participant)
my.fe44

my.fe45 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + jcs.score.dw + President| District  + Month + Year, data = alltrials)
my.fe45 <- summary(my.fe45, cluster = ~Case + Participant)
my.fe45


my.fe46 <- feols(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + jcs.score.dw + President| District + Month + Year, data = alltrials)
my.fe46 <- summary(my.fe46, cluster = ~Case + Participant)
my.fe46

table18 <- modelsummary(models = list("Any Incarceration (All)" = my.fe44, "Incarceration Length (Trials)" = my.fe45, "Incarceration Length More than 30 Years (Trials)" = my.fe46), stars = TRUE, integer = 5, output = "tabJCSa.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:JCS}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")


### Table 18 in the Appendix


table18

############
# dropping the felony variable
############


my.fe47 <- feols(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + President | District  + Month + Year, data = allsentences)
my.fe47 <- summary(my.fe47, cluster = ~Case + Participant)
my.fe47

my.fe48 <- feols(Incarceration.Trunc ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + President| District  + Month + Year, data = alltrials)
my.fe48 <- summary(my.fe48, cluster = ~Case + Participant)
my.fe48


my.fe49 <- feols(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + President| District + Month + Year, data = alltrials)
my.fe49 <- summary(my.fe49, cluster = ~Case + Participant)
my.fe49

table19 <- modelsummary(models = list("Any Incarceration (All)" = my.fe47, "Incarceration Length (Trials)" = my.fe48, "Incarceration Length More than 30 Years (Trials)" = my.fe49), stars = TRUE, integer = 5, output = "tabFelonyOmita.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (LPM). For Column 2, outcome is truncated sentence length (OLS). For Column 3, outcome is whether incarceration is longer than 30 years (LPM). For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district, month, year, and identity of appointing president.\\label{t:felony-omit}', coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

### Table 19 in the Appendix


table19


############
# repeating key results as a logit (requested by a reviewer)
############


# Run fixed effects logit model
my.fe50 <- glm(I(Incarceration.Tot > 0) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President + District + Month + Year,
  data = allsentences, family = "binomial")
my.fe50 <-  summary(my.fe50, type="clustered", cluster=~Case + Participant)

#Table 20 in appendix
my.fe50



my.fe52 <- glm(I(Incarceration.Trunc > (30*12)) ~ pub.defender + prosecutor + I(Priv.Criminal.Defense == 1) + I(Gender == "Female") + as.factor(Race.or.Ethnicity) + as.numeric(Commission.Year..1.) + I(chg_type == "F") + President + District + Month + Year, data = alltrials, family = "binomial")
#Gmy.fe52 <- summary(my.fe52, cluster = ~Case + Participant)
my.fe52 <-  summary(my.fe52, type="clustered", cluster=~Case + Participant)

#Table 21 in appendix
my.fe52


modelsummary(models = list("Any Incarceration (All)" = my.fe50, "Incarceration Length More than 30 Years (Trials)" = my.fe52), stars = TRUE, integer = 5, output = "tabLogitAppendix.tex", threeparttable = TRUE, title = 'For Columns 1, outcome is whether sentence (if any) included  any incarceration (all sentences). For Column 2, outcome is whether incarceration is longer than 30 years (for trials only). All models use a logit specification. For all models, standard errors clustered at the case and defendant level. Models include fixed effects for district (not shown), month (not shown), year (not shown), and identity of appointing president (shown).\\label{t:logit}', coef_omit = "Year*|District*|Month*", coef_rename = aa, gof_omit = "Std*|IC|Adj|Pseudo|Within")

gg <- xtable(my.fe50, digits = 3, caption = "Outcome is whether sentence (if any) included any incarceration (all sentences). Model uses a logit specification. Standard errors are clustered at the case and defendant level. Models include fixed effects for district (not shown), month (not shown), year (not shown), and identity of appointing president (shown).\\label{t:logit1}")
hh <- xtable(my.fe52, digits = 3, caption = "Outcome is whether incarceration is longer than 30 years (for trials only). Model uses a logit specification. Standard errors are clustered at the case and defendant level. Models include fixed effects for district (not shown), month (not shown), year (not shown), and identity of appointing president (shown).\\label{t:logit2}")


rownames(gg)[1:17] <- c("(Intercept)","Former Pub Defender", "Former Prosecutor", "Private Criminal Defense Experience" ,"Female", "African American Judge", "Judge Race Other" ,"Judge Commission Year", "Charge is a Felony","PresidentDonald J. Trump"="Trump Appointee", "PresidentJohn F. Kennedy"="Kennedy Appointee", "PresidentGeorge W. Bush"="Bush II Appointee","PresidentGeorge H.W. Bush"="Bush I Appointee","PresidentJimmy Carter"="Carter Appointee","PresidentRichard M. Nixon"="Nixon Appointee","PresidentLyndon B. Johnson"="Johnson Appointee","PresidentGerald Ford"="Ford Appointee")

rownames(hh)[1:17] <- c("(Intercept)","Former Pub Defender", "Former Prosecutor", "Private Criminal Defense Experience" ,"Female", "African American Judge", "Judge Race Other" ,"Judge Commission Year", "Charge is a Felony","PresidentDonald J. Trump"="Trump Appointee", "PresidentJohn F. Kennedy"="Kennedy Appointee", "PresidentGeorge W. Bush"="Bush II Appointee","PresidentGeorge H.W. Bush"="Bush I Appointee","PresidentJimmy Carter"="Carter Appointee","PresidentRichard M. Nixon"="Nixon Appointee","PresidentLyndon B. Johnson"="Johnson Appointee","PresidentGerald Ford"="Ford Appointee")



print(gg[1:16,], file = "tabLogitAppendix1.tex")
print(hh[1:16,], file = "tabLogitAppendix2.tex")


#################################################################
## Misc: TRAC Data Codes That May be of Use
#################################################################

# Disposition Type
# Criminal
# DE	Declination
# DJ	Dismissed with prejudice
# DM	Dismissed without prejudice
# DP	Dism prejudice (code retired)
# GD	Adjudged juvenile delinquent
# GT	Guilty
# ID	Immediate declination
# NB	No true bill
# NC	Nolo contendere
# ND	Adjudged NOT juvenile delinquent
# NG	Not guilty
# NW	New filing
# OC	Charge included in other case
# OE	Opened in Error/Office Error
# RE	Removal
# SU	Superseded (code retired)
# TR	Transfer
# Codes for Appeals
# FA	Appeal disposal favorable to United States
# NF	Appeal disposal NOT favorable to United States
# DA	Appeal dismissed by appellant

# Criminal Other Than Declinations

# ACGJ	By Action of the Grand Jury (No true bill)
# ACRD	Rule 29 (directed verdict or JNOV) (District Court)
# ACRM	Rule 29 (directed verdict or JNOV) (Magistrate Court) (Added by September 1997)
# BTRD	Bench Trial Verdict (District Court)
# BTRM	Bench Trial Vedict (Magistrate Court)
# CITA	Citation filed
# CMPL	Complaint filed
# DEMD	By defense motion (District Court)
# DEMM	By defense motion (Magistrate Court)
# DETH	Death of Defendant
# DFOC	Defendant Similarly Charged in Subsequent Instrument (Added by September 1997)
# EXTR	Extradition
# FOFS	Final order of forfeiture/assets substituted
# GWDD	By government from District Court w/ DOJ authorization
# GWDM	By government from Magistrate Court w/ DOJ authorization
# GWOD	By government from District Court no DOJ authorization
# GWOM	By government from Magistrate Court no DOJ authorization
# HUND	Hung Jury (District Court)
# HUNM	Hung Jury (Magistrate Court)
# INBD	By Reason of Insanity (Bench Trial)
# INDT	Indictment filed (following a complaint filing)
# INDV	By Reason of Insanity (Directed Verdict)
# INFO	Information Filed (following a complaint filing)
# INJD	By Reason of Insanity (Jury Trial)
# JOID	Joinder (District Court) in which there is only
# one defendant to be joined with other defendants in another case.
# JOIM	Joinder (Magistrate Court) in which there is only
# one defendant to be joined with other defendants in another case.
# JTRD	Jury Trial Verdict (District Court)
# JTRM	Jury Trial Verdict (Magistrate Court)
# MISD	Mistrial (District Court)
# MISM	Mistrial (Magistrate Court)
# OEOE	Opened in Error/Office Error
# OPLD	Operation of Law (District Court)
# OPLM	Operation of Law (Magistrate Court)
# PEPO	Petite Policy (Added by September 1997)
# PFAH	Final Order of Forfeiture in Favor of Government
# PLED	Plea (District Court)
# PLEM	Plea (Magistrate Court)
# PLOD	Plea to other charge(s) (District Court)
# PLOM	Plea to other charge(s) (Magistrate Court)
# PNFA	Final Order of Forfeiture in Favor of Claimant
# PSRI	Proceedings suspended indefinitely by court (Discontinued by September 1995)
# PTDR	Pretrial Diversion Completed
# PUCP	Plea to Underlying Complaint (Discontinued by September 1995)
# RESM	Restitution/Arrearage Payments Made
# or Being Made (Magistrate Court) (Added by September 1997)
# RESD	Restitution/Arrearage Payments Made
# or Being Made (District Court) (Added by September 1997)
# RTOD	Rule 21 (District Court)
# RTOM	Rule 21 (Magistrate Court)
# RTWD	Rule 20 (District Court)
# RTWM	Rule 20 (Magistrate Court)
# RUFO	Rule 40
# SEVD	Severance (District Court) (Discontinued by September 1995)
# SEVM	Severance (Magistrate Court) (Discontinued by September 1995)
# SIFD	Superseding Information (From District Court)
# SIFM	Superseding Information (From Magistrate Court)
# SIND	Superseding Indictment (From District Court)
# SINM	Superseding Indictment (From Magistrate Court)
# SSCD	Sua Sponte by District Court (courts own initiative)
# SSCM	Sua Sponte by Magistrate Court (courts own initiative)
# STAD	State Authorities from District Court
# (e.g., UFAPs where UFAP charges were filed)
# STAM	State Authorities from Magistrate Court
# (e.g., UFAPs where UFAP charges were file)
# STRD	Speedy Trial Act Violation (District Court)
# STRM	Speedy Trail Act Violation (Magistrate Court)
# TROU	Transfer within District (Discontinued by September 1997)


# INCARCERATION TYPE
# CON Concurrent
# COS Consecutive
# DBS Defendant Died Before Sentence
# DET Death (unclear)
# LIF Life
# TIM Time Served

# GUIDELINES DEPARTURE
# A Upward Departure Supported by U.S.
# B Upward Departure Opposed by U.S.
# D Other Downward Departure Supported by U.S.
# E Other Downward Departure Opposed by U.S.
